package main

import (
	"log"
	"time"
)

type query struct {
	sql    chan string
	resutl chan string
}

func execQuery(q query) {
	go func() {
		sql := <-q.sql

		// 数据库处理

		q.resutl <- "result form " + sql
	}()
}

func main() {
	q := query{}
	q.sql = make(chan string)
	q.resutl = make(chan string)
	// 执行
	go execQuery(q)

	q.sql <- "select * from user"

	// 开始做其他事情
	time.Sleep(1 * time.Second)
	log.Println(<-q.resutl)
}
